package chapter15;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/23 10:46
 */
public class LockCounter implements ICounter {
    private int count;
    private Object lock;

    public LockCounter() {
        count = 0;
        this.lock = new Object();
    }

    @Override
    public void incr() {
        synchronized (lock) {
            count++;
        }
    }

    @Override
    public int getCount() {
        synchronized (lock) {
            return count;
        }
    }
}
